/*
    拼接字符串
 */
public class PasteString {
    public static void main(String[] args) {
        long l1 = System.currentTimeMillis();
        int[] arr = {1,2,2,4,5};

        System.out.println(s(arr));

        long l2 = System.currentTimeMillis();
        System.out.println(l2 - l1);
    }
    //拼接字符串
    public static String s(int[] arr){
        StringBuilder sb = new StringBuilder();

        sb.append("[");//首位
        for (int i = 0; i < arr.length; i++) {
            sb.append(arr[i]);//挨个加入StringBuilder
            if (i != arr.length-1){
                sb.append(',');//非末位加,分隔
            }
        }
        sb.append("]");//末位

        String s = sb.toString();//SBuilder转为String,便于返回
        return s;
    }

}
